﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TGIApp.Model;
using TGIApp.Data;
using TGIApp.Data.EntityFramework;


namespace TGIApp.Business
{
    public class TgiService: ITgiService
    {
        private IRepository repository;
        public TgiService()
        {
        }
       
       
        public Event GetEventById(int id)
        {
            throw new NotImplementedException();
        }

        public List<Role> GetAllRoles()
        {
            throw new NotImplementedException();
        }


        public void CreateRole(Role role)
        {
           repository = new GenericRepository();
            repository.UnitOfWork.BeginTransaction(isolationLevel: System.Data.IsolationLevel.ReadCommitted);
            repository.Add(role);
            repository.UnitOfWork.CommitTransaction();
            
            

        }

        public List<User> GetAllClients()
        {
            repository = new GenericRepository();
            var clients= repository.GetAll<User>().Where(user => user.UserType == 2).ToList();
            return clients;
        }

        public User GetClientById(int id)
        {
            repository = new GenericRepository();
            var client = repository.GetByKey<User>(id);
            client.Address = repository.GetByKey<Address>(client.Address_Id);
            //repository.Get(null,0,0,)
            return client;
        }

        public void CreateClient(User user)
        {
            repository = new GenericRepository();
            try
            {
                repository.UnitOfWork.BeginTransaction();
                user.UserType = 2;
                user.Role_Id = 2;
                repository.Add(user.Address);
                repository.Add<User>(user);
                repository.UnitOfWork.CommitTransaction();
            }
            catch (Exception)
            {
                repository.UnitOfWork.RollBackTransaction();
                throw;
            }
            
        }

        public void UpdateClient(User user)
        {
            repository = new GenericRepository();
            try
            {
                repository.UnitOfWork.BeginTransaction();
                user.UserType = 2;
                user.Role_Id = 2;
                repository.Update<Address>(user.Address);
                repository.Update<User>(user);
                repository.UnitOfWork.CommitTransaction();
            }
            catch (Exception)
            {
                repository.UnitOfWork.RollBackTransaction();
                throw;
            }
        }

        public void DeleteClient(User user)
        {
            repository = new GenericRepository();
            try
            {
                repository.UnitOfWork.BeginTransaction();
                repository.Attach<User>(user);
                repository.Attach<Address>(user.Address);
                repository.Delete<User>(user);
                repository.Delete<Address>(user.Address);
                repository.UnitOfWork.CommitTransaction();
            }
            catch (Exception)
            {
                repository.UnitOfWork.RollBackTransaction();
                throw;
            }
        }

        public void DeleteClientById(int id)
        {
            repository = new GenericRepository();
            try
            {
                repository.UnitOfWork.BeginTransaction();
                User user = repository.GetByKey<User>(id);
                repository.Delete<User>(u=>u.Id==id);
                repository.Delete<Address>(u => u.Id == user.Address_Id);
                repository.UnitOfWork.CommitTransaction();
            }
            catch (Exception)
            {
                repository.UnitOfWork.RollBackTransaction();
                throw;
            }
        }

        public List<User> GetAllAgents()
        {
            throw new NotImplementedException();
        }

        public User GetAgentById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreateAgent(User user)
        {
            throw new NotImplementedException();
        }

        public void UpdateAgent(User user)
        {
            throw new NotImplementedException();
        }

        public void DeleteAgent(User user)
        {
            throw new NotImplementedException();
        }

        public void DeleteAgentById(int id)
        {
            throw new NotImplementedException();
        }

        public List<User> GetAllCustomers()
        {
            throw new NotImplementedException();
        }

        public User GetCustomerById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreateCustomer(User user)
        {
            throw new NotImplementedException();
        }

        public void UpdateCustomer(User user)
        {
            throw new NotImplementedException();
        }

        public void DeleteCustomer(User user)
        {
            throw new NotImplementedException();
        }

        public void DeleteCustomerById(int id)
        {
            throw new NotImplementedException();
        }

        public Role GetRoleById(int id)
        {
            throw new NotImplementedException();
        }

        public void UpdateRole(Role role)
        {
            throw new NotImplementedException();
        }

        public void DeleteRole(Role role)
        {
            throw new NotImplementedException();
        }

        public void DeleteRoleById(int id)
        {
            throw new NotImplementedException();
        }

        public List<Event> GetAllEvents()
        {
            throw new NotImplementedException();
        }

        public void CreateEvent(Event evnt)
        {
            throw new NotImplementedException();
        }

        public void UpdateEvent(Event evnt)
        {
            throw new NotImplementedException();
        }

        public void DeleteEvent(Event evnt)
        {
            throw new NotImplementedException();
        }

        public void DeleteEventById(int id)
        {
            throw new NotImplementedException();
        }

        public List<Venue> GetAllVenues()
        {
            throw new NotImplementedException();
        }

        public Venue GetVenueById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreateVenue(Venue venue)
        {
            throw new NotImplementedException();
        }

        public void UpdateVenue(Venue venue)
        {
            throw new NotImplementedException();
        }

        public void DeleteVenue(Venue venue)
        {
            throw new NotImplementedException();
        }

        public void DeleteVenueById(int id)
        {
            throw new NotImplementedException();
        }

        public List<Ticket> GetAllTickets()
        {
            throw new NotImplementedException();
        }

        public Ticket GetTicketById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreatTicket(Ticket ticket)
        {
            throw new NotImplementedException();
        }

        public void UpdateTicket(Ticket ticket)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicket(Ticket ticket)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicketById(int id)
        {
            throw new NotImplementedException();
        }

        public List<TicketType> GetAllTicketTypes()
        {
            throw new NotImplementedException();
        }

        public TicketType GetTicketTypeById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreatTicketType(TicketType ticketType)
        {
            throw new NotImplementedException();
        }

        public void UpdateTicketType(TicketType ticketType)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicketType(TicketType ticketType)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicketTypeById(int id)
        {
            throw new NotImplementedException();
        }

        public List<TicketTemplate> GetAllTicketTemplates()
        {
            throw new NotImplementedException();
        }

        public TicketTemplate GetTicketTemplateById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreatTicketTemplate(TicketTemplate ticketTemplate)
        {
            throw new NotImplementedException();
        }

        public void UpdateTicketTemplate(TicketTemplate ticketTemplate)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicketTemplate(TicketTemplate ticketTemplate)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicketTemplateById(int id)
        {
            throw new NotImplementedException();
        }

        public List<TicketQuota> GetAllTicketQuotas()
        {
            throw new NotImplementedException();
        }

        public TicketQuota GetTicketQuotaById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreatTicketQuota(TicketQuota ticketQuota)
        {
            throw new NotImplementedException();
        }

        public void UpdateTicketQuota(TicketQuota ticketQuota)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicketQuota(TicketQuota ticketQuota)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicketQuotaById(int id)
        {
            throw new NotImplementedException();
        }

        public List<Payment> GetAllPayments()
        {
            throw new NotImplementedException();
        }

        public Payment GetPaymentById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreatePayment(Payment payment)
        {
            throw new NotImplementedException();
        }

        public void UpdatePayment(Payment payment)
        {
            throw new NotImplementedException();
        }

        public void DeletePayment(Payment payment)
        {
            throw new NotImplementedException();
        }

        public void DeletePaymemntById(int id)
        {
            throw new NotImplementedException();
        }
    }
}
